<style>
  .header-font {
    font-size: 15px;
    font-weight: bold;
  }
  .line {
    margin: 10px 0;
    width: 100%;
    border: 0.5px solid rgb(218, 218, 218);
  }
  .table {
    margin-top:10px;
  }
  .personnel-form {
    margin-bottom: -10px;
  }
  .paging {
    float:right;
    margin-top:10px;
  }
  .btn-export {
    float: left;
  }
  .btn-upload {
    float: left;
  }
</style>
<template>
  <div>
    <div class='header-font'>
      <Icon type="md-apps" />
      <span>人事管理今日报表</span>
    </div>
    <div class="line"></div>
    <personnel-form
      @on-success-valid="handleSubmit"
      class="personnel-form">
    </personnel-form>
    <Button
      icon="md-add"
      type="primary"
      @click="handleClick">
      添加
    </Button>
    <!-- <btn-export :tableData="personnelList" :tableTitle="columns" :title="title" class="btn-export"></btn-export> -->
    <!-- <btn-upload class="btn-upload" :title="title"></btn-upload> -->
    <personnel-modal
      @personnel-valid="handleEdit">
    </personnel-modal>
    <Table
      :columns="columns"
      :data="historyData"
      border
      class="table">
    </Table>
    <table-page
      class="paging"
      :dataCount="dataCount"
      @change-page="changePage"
      :pageSize="pageSize">
    </table-page>
  </div>
</template>
<script>
import {
  mapActions,
  mapState
} from 'vuex'
import PersonnelForm from '_c/personnel-form'
import PersonnelModal from '_c/personnel-modal'
import TablePage from '_c/page'
import BtnExport from '_c/btn-export'
import BtnUpload from '_c/btn-upload'
export default {
  components: {
    PersonnelForm,
    PersonnelModal,
    TablePage,
    BtnExport,
    BtnUpload
  },
  data () {
    return {
      page: 1,
      title: '人事管理今日报表',
      columns: [
        {
          title: '序号',
          type: 'index2',
          width: 60,
          align: 'center',
          fixed: 'left',
          render: (h, params) => {
            return h('span', params.index + (this.page - 1) * this.pageSize + 1)
          }
        },
        {
          title: '应聘者',
          key: 'name',
          width: 100,
          align: 'center',
          fixed: 'left'
        },
        {
          title: '联系方式',
          key: 'tel',
          width: 120,
          align: 'center'
        },
        {
          title: '应聘岗位',
          key: 'job',
          width: 100,
          align: 'center'
        },
        {
          title: '初试时间',
          key: 'viewtime',
          align: 'center',
          width: 100,
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.viewtime ? this.$moment(params.row.viewtime).format('YYYY-MM-DD') : '-'
            )
          }
        },
        {
          title: '初试时长',
          key: 'viewhour',
          width: 100,
          align: 'center'
        },
        {
          title: '初试结果',
          key: 'viewresult',
          width: 100,
          align: 'center'
        },
        {
          title: '是否复试',
          key: 'isreview',
          width: 100,
          align: 'center',
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.isreview === '0' ? '否' : '是'
            )
          }
        },
        {
          title: '复试时间',
          key: 'reviewtime',
          align: 'center',
          width: 100,
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.reviewtime ? this.$moment(params.row.reviewtime).format('YYYY-MM-DD') : '-'
            )
          }
        },
        {
          title: '复试结果',
          key: 'reviewresult',
          width: 100,
          align: 'center'
        },
        {
          title: '入职时间',
          key: 'entrytime',
          align: 'center',
          width: 100,
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.entrytime ? this.$moment(params.row.entrytime).format('YYYY-MM-DD') : '-'
            )
          }
        },
        {
          title: '入职部门',
          key: 'entrydepart',
          width: 100,
          align: 'center'
        },
        {
          title: '入职地点',
          key: 'entryaddress',
          width: 100,
          align: 'center'
        },
        {
          title: '渠道来源',
          key: 'pcode',
          width: 100,
          align: 'center'
        },
        {
          title: '面试状态',
          key: 'state',
          align: 'center',
          width: 100,
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.state === '-1' ? '预约未到' : params.row.state === '0' ? '面试中' : params.row.state === '1' ? '面试录用' : params.row.state === '2' ? '面试不录用' : '-'
            )
          }
        },
        {
          title: '最近修改时间',
          key: 'uptime',
          align: 'center',
          width: 150,
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.uptime ? this.$moment(params.row.uptime).format('YYYY-MM-DD HH:mm:ss') : '-'
            )
          }
        },
        {
          title: '创建时间',
          key: 'ctime',
          align: 'center',
          width: 150,
          render: (h, params) => {
            return h(
              'span',
              {},
              params.row.ctime ? this.$moment(params.row.ctime).format('YYYY-MM-DD HH:mm:ss') : '-'
            )
          }
        },
        {
          title: '操作',
          key: 'cz',
          align: 'center',
          width: 150,
          fixed: 'right',
          render: (h, params) => {
            return h('div', [
              h('Button', {
                props: {
                  type: 'primary',
                  size: 'small',
                  ghost: 'ghost'
                },
                style: {
                  marginRight: '5px'
                },
                on: {
                  click: () => {
                    this.handleClick(params.row.id, params.row)
                  }
                }
              }, '修改')
            ])
          }
        }
      ]
    }
  },
  computed: {
    ...mapState({
      personnelList: state => state.personnel.personnelList,
      dataCount: state => state.personnel.personnelDataCount,
      historyData: state => state.personnel.personnelHistoryData,
      pageSize: state => state.personnel.pageSize
    })
  },
  methods: {
    ...mapActions([
      'getPersonnelList',
      'updateModalState',
      'updatePersonnelData',
      'getPersonnelCurrentRow',
      'changePersonnelPage'
    ]),
    handleSubmit (playload) {
      this.getPersonnelList(playload)
    },
    handleClick (id, row) {
      let newRow = {}
      this.id = id
      if (row) {
        newRow = Object.assign({}, row)
      }
      this.getPersonnelCurrentRow(newRow)
      this.updateModalState(true)
    },
    handleEdit (playload, id) {
      this.updatePersonnelData(playload).then(
        setTimeout(() => {
          this.getPersonnelList({ page: this.page })
        }, 100)
      )
      this.updateModalState(false)
    },
    changePage (index) {
      this.page = index
      this.changePersonnelPage(index)
      this.getPersonnelList({ page: index })
    }
  },
  created () {
    this.getPersonnelList({})
  }
}
</script>
